rm(list=ls())
library(tidyverse)

load("data/counts/counts_fl09.RData")


wide = tibble(
  dob = unique(data$birthdate),
  
 
  vote2008_white = NA,
  vote2008_black = NA,
  vote2008_hispanic = NA
  
  
  
              
              
)
for(i in 1:length(wide$dob)){
  wide$vote2008_white[i] = ifelse(length(data$vote[data$electiondate == "2008-11-04" & data$race == 5 & data$birthdate == wide$dob[i]])>=1,data$vote[data$electiondate == "2008-11-04" & data$race == 5 & data$birthdate == wide$dob[i]],0)
  wide$vote2008_black[i] = ifelse(length(data$vote[data$electiondate == "2008-11-04" & data$race == 3 & data$birthdate == wide$dob[i]])>=1,data$vote[data$electiondate == "2008-11-04" & data$race == 3 & data$birthdate == wide$dob[i]],0)
  wide$vote2008_hispanic[i] = ifelse(length(data$vote[data$electiondate == "2008-11-04" & data$race == 4 & data$birthdate == wide$dob[i]])>=1,data$vote[data$electiondate == "2008-11-04" & data$race == 4 & data$birthdate == wide$dob[i]],0)
  
 


}

data = as.data.table(wide)

data[is.na(vote2008_white), vote2008_white:=0]
data[is.na(vote2008_black), vote2008_black:=0]
data[is.na(vote2008_hispanic), vote2008_hispanic:=0]


rm(wide)
gc()

save(data, file = "data/analysis/rdd_fl09.Rdata")

###########


